package com.lesama.method;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

public class ThreadNameDemo3 {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        MyCall mc = new MyCall();
        FutureTask<Integer> ft1 = new FutureTask<>(mc);
        FutureTask<Integer> ft2 = new FutureTask<>(mc);

        Thread t1 = new Thread(ft1, "线程1");
        Thread t2 = new Thread(ft2, "线程2");
        t1.start();
        t2.start();
        Integer res1 = ft1.get();
        Integer res2 = ft2.get();

        System.out.println(t1.getName() + "的结果是" + res1);
        System.out.println(t2.getName() + "的结果是" + res1);
    }
}

class MyCall implements Callable<Integer> {

    @Override
    public Integer call() throws Exception {
        int sum = 0;
        for (int i = 0; i < 100; i++) {
            sum += i;
        }
        return sum;
    }
}
